$(document).ready(function($){
    
    // give main menu its functionality
    // see http://www.prowebdesign.ro/how-to-deal-with-hover-on-touch-screen-devices/ for touchscreen support
    
    if (!("ontouchstart" in document.documentElement)) {
        document.documentElement.className += " no-touch";
    }
    
    if (!$('html').hasClass('no-touch')) { //Execute code only on a touch screen device   

        $('li.main-menu').click(function(event) {
            $(this).parent().find('li.sub-menu').hide(); // hide all submenus
            var submenuItems = $(this).find('li');
            if ($(submenuItems).first().css('display') !== 'block') { // submenu not visible at this point
                $(submenuItems).show(); // make items visible
            }
            event.stopPropagation();
        });
                
        //Close filters drop-downs if user taps ANYWHERE in the page
        $(document).bind('touchstart', function(e) {               
            $("#nav ul").hide();
        });         
    }
    
    $('#nav li.sub-menu').click(function() {
        window.location.replace($(this).find('a').first().attr('href'));
    });



//            $(document).mousemove(function(event) {
//                if (event.pageY <= 20 && $('#top-section').attr('display') != 'block') {
//                    $('#top-section').fadeIn();
//                } else {
//                    if (event.pageY >= 20 && $('#top-section').attr('display') == 'block') {
//                        $('#top-section').fadeOut();
//                    }
//                }
//            });
});